<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入axios -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

</head>
<body>
    <h1>跨域</h1>
    <button id="btn">发送请求</button>
    <script>
        //配置axios实例,通过不同的实例实现不同的功能
        const myaxios = axios.create({
            baseURL: "http://127.0.0.1:1234",
            timeout: 1000,
            headers: {}
        })

        //浏览器的同源策略是的请求失败
        const oBtn = document.getElementById("btn")
        btn.onclick = async function(){
           const result = await myaxios.get("/pUser",{
                params: {
                    // 根据userID获取相关的信息
                    userID: "001"
                }
            })
            console.log("result",result);
        }
    </script>
</body>
</html>